package cn.cs.service;

import cn.cs.common.IdWorker;
import cn.cs.mapper.CsTradeMapper;
import cn.cs.pojo.CsTrade;
import cn.cs.vo.DmItemMessageVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.RequestMapping;


import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

/**
 * yuexl
 */
@RestController
public class RestCsTradeService {
    private static final Logger logger = LoggerFactory.getLogger(RestCsTradeService.class);
     @Resource
     private CsTradeMapper csTradeMapper;
     @Resource
     private RabbitTemplate rabbitTemplate;


    @RequestMapping(value = "/insertTrade",method = RequestMethod.POST)
    public Integer insertTrade(@RequestBody DmItemMessageVo dmItemMessageVo) throws Exception {
        CsTrade csTrade = new CsTrade();
        csTrade.setId(IdWorker.getId().toString());
        csTrade.setAmount(dmItemMessageVo.getAmount());
        csTrade.setCreatedTime(Calendar.getInstance().getTime());
        csTrade.setOrderNo(dmItemMessageVo.getOrderNo());
        csTrade.setPayMethod(1);
        csTrade.setTradeNo(dmItemMessageVo.getTradeNo());
//        发送消息修改订单状态
        rabbitTemplate.convertAndSend("topicExchange", "key.toUpdateOrder", dmItemMessageVo);
        logger.info("[insertTrade]" + "发送消息成功，消息的内容为："+dmItemMessageVo.toString());
        return csTradeMapper.insertCsTrade(csTrade);
    }
}
